﻿using System.Collections.Generic;

namespace StartupSolution.Web.Services
{
    public class DataService : IDataService
    {
        // Create a collection of TestData objects
        private TestDataCollection internalData = new TestDataCollection();

        public DataService()
        {
            // Generate some test data for the sample
            GenerateTestData();
        }

        // Generate a huge amount of TestData, in this case we will create a collection of 1000 records.
        private void GenerateTestData()
        {
            for (int i = 0; i < 1000; i++)
            {
                internalData.Add(new TestData() { Index = i, Entry = "Test Data Record " + i });
            }

        }

        public int GetTestDataCount()
        {
            return internalData.Count;
        }

        // Request a certain amount of data
        public TestDataResult GetTestData(int start, int size)
        {
            TestDataResult tdr = new TestDataResult();
            
            TestDataCollection tdc = new TestDataCollection();
            
            List<TestData> res = internalData.GetRange(start, size);

            foreach (TestData td in res)
            {
                tdc.Add(td);
            }

            tdr.StartIndex = start;
            tdr.DataItems = tdc;

            return tdr;
        }


    }
}
